#ifndef _TRACK_H_
#define _TRACK_H_

#include "Box2D\Box2D.h"
#include <vector>

class EdgeBuilder
{
private:
	b2BodyDef               a_bodyDef;
	b2EdgeShape             a_shape;
	b2FixtureDef            a_fixtureDef;
	std::vector<b2Vec2>     a_segmentVector;
	b2Vec2                  a_lastAppliedPoint;
public:
	EdgeBuilder();
	~EdgeBuilder();
	void setDefaultValues();
	void extendSegmentVectorWith(b2Vec2 translation);
	void beginNewSegmentFrom(b2Vec2 point);
	void clearSegmentVector();
	void applySegmentTo(b2Body* p_body);  // TO DO : problem with wrong body
	b2Vec2 getLastAppliedPoint();         // TO DO : get when not set
};


class Track: public b2ContactListener  // TO DO : no =operator and copy constructorrrrrrrr!!!111eleven (so many pointerssss!)
{
private:
	b2Body*             ap_groundBody;
	EdgeBuilder          a_edgeBuilder;
	b2World*            ap_gameWorld;
	b2Body*             ap_trampoline;
	b2PrismaticJoint*   ap_trampolineJoint;
	b2Vec2               a_lastPoint;
protected:
	void connectToGameWorld(b2World* p_gameWorld);
	void buildTrack(b2Vec2 position);
	void biuld_1st_stage();
	void biuld_pipe_to_second_stage();
	void biuld_2nd_stage();
	void extendTrackSegmentWith(b2Vec2 translation, std::vector<b2Vec2>& r_trackSegment);
	void disconnectFromGameWorld();
	Track();
public:
	Track(b2World* p_gameWorld, b2Vec2 position);
	void BeginContact(b2Contact* contact);
	void EndContact(b2Contact* contact);
	~Track();
};

#endif

/* EXAMPLE
b2Body*  ap_gravitySensor1;
b2Body*  ap_gravitySensor2;
b2Body*  ap_gravitySensor3;
b2Body*  ap_backToStartElevator;
*/